import { Injectable } from "@nestjs/common";


export enum StoreKey {
    ONLINE_USER_IDS = "online_user_ids"
}


interface StoreValue {
    [StoreKey.ONLINE_USER_IDS]: Set<number>
}


@Injectable()
export class StoreService {
    public store = new Map<StoreKey, any>();

    public set<K extends StoreKey>(key: K, value: StoreValue[K]) {
        this.store.set(key, value);
    }

    public get<K extends StoreKey>(key: K, defalut?: StoreValue[K]): StoreValue[K] {
        return this.store.get(key) || defalut;
    }

    public has(key: StoreKey) {
        return this.store.has(key);
    }

    public del(key: StoreKey) {
        return this.store.delete(key);
    }
}
